﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.Linq.Expressions;
using System.Reflection;
using Newtonsoft.Json;
using Microsoft.Kinect.Toolkit.Interaction;
using Microsoft.Kinect;

namespace jKinect
{
    public class JSONableEventArgs : EventArgs
    {
        public override string ToString()
        {
            return JsonConvert.SerializeObject(this);
        }
    }

    [Serializable]
    public class JSONableEventArgs<T> : JSONableEventArgs
    {
        public T Data { get; set; }
        public JSONableEventArgs(T data)
            : base()
        {
            Data = data;
        }
    }

    public class ParamEventArgs : EventArgs
    {
        public object Param { get; set; }
        public ParamEventArgs(object parameter)
            : base()
        {
            Param = parameter;
        }
    }
    public class ParamsEventArgs : EventArgs
    {
        public object[] Params { get; set; }
        public ParamsEventArgs(params object[] parameters)
            : base()
        {
            Params = parameters;
        }
    }

    public class JointEventArgs : JSONableEventArgs
    {
        public Microsoft.Kinect.SkeletonPoint Position { get; set; }
        public JointEventArgs(Microsoft.Kinect.SkeletonPoint position)
            : base()
        {
            Position = position;
        }
    }

    public class JointsDictionary : Dictionary<string, Microsoft.Kinect.SkeletonPoint>
    {
    }

    public class PlayersJoints : List<JointsDictionary>
    {
    }

    public class JointsEventArgs : JSONableEventArgs
    {
        public JointsDictionary Joints { get; set; }
        public InteractionHandPointer[] HandPointers { get; set; }
        public JointsEventArgs(JointsDictionary joints, InteractionHandPointer[] handPointers)
            : base()
        {
            Joints = joints;
            HandPointers = handPointers;
        }
    }

    public class PositionEventArgs : JSONableEventArgs
    {
        public Microsoft.Kinect.SkeletonPoint Position { get; set; }
        public PositionEventArgs(Microsoft.Kinect.SkeletonPoint position)
            : base()
        {
            Position = position;
        }
    }

    public class PlayerStatusEventArgs : JSONableEventArgs
    {
        public int PlayerIndex { get; set; }
        public string Status { get; set; }
        public Microsoft.Kinect.SkeletonPoint Position { get; set; }

        public int PlayersCount { get; set; }
        public PlayerStatusEventArgs(int playerIndex, string status, Microsoft.Kinect.SkeletonPoint position, int playersCount)
            : base()
        {
            PlayerIndex = playerIndex;
            PlayersCount = playersCount;
            Status = status;
            Position = position;
        }

    }

    public class AllPlayersJointsEventArgs : JSONableEventArgs
    {
        public PlayersJoints Players { get; set; }

        public AllPlayersJointsEventArgs()
            : base()
        {
            Players = new PlayersJoints();
        }

        public void AddPlayerJoints(int playerIndex, JointsDictionary joints)
        {
            Players.Add(joints);
        }
    }

    public class AllFramesReallyReadyEventArgs : EventArgs
    {
        public SkeletonFrame SkeletonFrame { get; set; }
        public DepthImageFrame DepthFrame { get; set; }
        public AllFramesReallyReadyEventArgs(SkeletonFrame skeletonFrame, DepthImageFrame depthFrame)
            : base()
        {
            SkeletonFrame = skeletonFrame;
            DepthFrame = depthFrame;
        }

    }
}
